package com.google.api.sncf;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;


public class DepartsView extends LinearLayout {

     private TextView mHDepart;
     private TextView mDestination;
     private TextView mTtransport;
     private TextView mCommentaire;
     private LinearLayout Container;
     
     //private View v;
     
     public DepartsView(Context context, String depart, String destination, String transport,String commentaire) {
    	 super(context);
         
         this.setOrientation(VERTICAL);
         //setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
         this.setWeightSum(100);
         
         Container = new LinearLayout(context);
         Container.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT,70));
         Container.setOrientation(HORIZONTAL);
         Container.setWeightSum(100);
         
         //Construction des TextView
         //Depart
         mHDepart = new TextView(context);
         mHDepart.setText(depart);
         mHDepart.setTextSize(25);
         mHDepart.setGravity(Gravity.CENTER);
 
         mHDepart.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT,40)); 
                  
         //Destination
         mDestination= new TextView(context);
         mDestination.setText(destination.toUpperCase());
         mDestination.setTextSize(20);
         mDestination.setGravity(Gravity.CENTER);

         mDestination.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT,20)); 

         //Type Transport
         mTtransport= new TextView(context);
         mTtransport.setText(transport);
         mTtransport.setTextSize(20);
         mTtransport.setGravity(Gravity.LEFT);

         mTtransport.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT,40)); 

         //CHILD ELEMENTS
         Container.addView(mHDepart);
         Container.addView(mDestination);
         Container.addView(mTtransport);

         //Commentaires
         mCommentaire= new TextView(this.getContext());
         //mCommentaire.setText(commentaire);
         setCommentaire(commentaire);
         mCommentaire.setBackgroundColor(Color.RED);
         mCommentaire.setTextSize(15); 
         mCommentaire.setGravity(Gravity.LEFT);

         mCommentaire.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT,30)); 

         //-------------------------------------------------
         //ROOT ELEMENT
         this.addView(Container);
         this.addView(mCommentaire);
     }

     /**
      * Convenience method to set the title of a DepartsView
      */
     public void setHdepart(String depart) {
    	 mHDepart.setText(depart);
     }

     public void setDestination(String destination) {
    	 mDestination.setText(destination);
     }

     public void setTtransport(String transport) {
    	 mTtransport.setText(transport);
     }
     public void setCommentaire(String commentaire) {
    	 mCommentaire.setText(commentaire);
    	 if (!commentaire.startsWith(" ")){
    		mCommentaire.setVisibility(View.VISIBLE);
    	}else{
    		mCommentaire.setVisibility(View.GONE);
    	}
     }
 }
